package com.example.recyclerviewfenzu.JAC;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.res.AssetManager;
import android.os.Bundle;

import com.example.recyclerviewfenzu.R;
import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JACActivity extends AppCompatActivity {

    private String json;

    private DataListBean dataListBean;
    private NestedScrollView scrollview;
    private RecyclerView reclclerview;
    private RecyclerViewAdapter1 adapter1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_j_a_c);
        scrollview = findViewById(R.id.scrollview);
        reclclerview = findViewById(R.id.reclclerview);
        json = getJson(this, "data.json");
        Gson gson = new Gson();
        dataListBean = gson.fromJson(json, DataListBean.class);
        adapter1=new RecyclerViewAdapter1(this,dataListBean.getData());
        reclclerview.setLayoutManager(new LinearLayoutManager(this));
        reclclerview.setNestedScrollingEnabled(false);
//取消recycleview的滑动
        reclclerview.setHasFixedSize(true);
        reclclerview.setAdapter(adapter1);

    }


    public static String getJson(Context context, String fileName) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open(fileName)));

            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException var6) {
            var6.printStackTrace();
        }
        return stringBuilder.toString();
    }
}
